<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=7"/>
    <title>悦定内容管理系统</title>

    <!--判断是否登陆-->
    <script type="text/javascript" src="../../vendor/jquery-2.0.3.min.js"></script>
    <script type="text/javascript" src="../../js/config.js"></script>
    <script type="text/javascript" src="../../js/jquerySession.js"></script>
    <!--<script type="text/javascript">-->
    <!--if ($.session.get('token') == null) {-->
    <!--alert("用户未登录！");-->
    <!--window.location.href = "../../login.html"-->
    <!--}-->
    <!--</script>-->

    <link href="../../css/common.css" rel="stylesheet">
    <link href="../../css/layout.css" rel="stylesheet">
    <link href="../../css/style_fy.css" rel="stylesheet">
    <script language="javascript" type="text/javascript" src="../../vendor/jquery.min.js"></script>
    <script language="javascript" type="text/javascript" src="../../js/admin_common.js"></script>
    <script language="javascript" type="text/javascript" src="../../js/styleswitch.js"></script>
    <script language="javascript" type="text/javascript" src="../../js/formvalidator.js" charset="UTF-8"></script>
    <script language="javascript" type="text/javascript" src="../../js/formvalidatorregex.js" charset="UTF-8"></script>
    <script type="text/javascript" charset="utf-8" src="../../vendor/kindeditor-all.js"></script>
    <script type="text/javascript" charset="utf-8" src="../../vendor/zh-CN.js"></script>
    <script type="text/javascript">
        var editor;
        KindEditor.ready(function (K) {
            editor = K.create('textarea[name="content"]', {
                uploadJson: baseUrl + '/uploadImage',//上传
                allowFileManager: false,
                allowImageUpload: true,
                fullScreenMode: false,
                afterBlur: function () {
                    this.sync();
                }  //数据同步
            });
        });
    </script>
    <script type="text/javascript">
        window.focus();
    </script>
    <style type="text/css">
        html {
            _overflow-y: scroll
        }

        body {

            background: #fff;

        }

        .add_btn {
            height: 60px;
            border-bottom: 1px solid #f2f2f2;
        }

        .add_btn button {
            width: 120px;
            height: 40px;
            margin-top: 10px;
            font-size: 20px;
            font-family: '微软雅黑';
        }

        .edit-list {
            margin: 0px 10px;
            float: left;
        }

        .edit-list li {
            height: 40px;
            line-height: 40px;
            font-size: 18px;
            margin: 30px 10px;
        }

        .edit-list li input {
            height: 34px;
            line-height: 34px;
            padding-left: 10px;
            font-size: 18px;

        }

        #newsCheckbox {

            width: 18px;
            height: 18px;
        }

    </style>
</head>
<body>


<!--头部-->
<div class="header" style="position: relative">
    <div class="logo"></div>
    <h1 class="logo">
        <a href="../user/participant.html" title="添加公告"><img src="../../images/logo.png" title="添加公告"></a>
    </h1>
    <div class="menu">
        <ul>

            <li class="current">
                <a href="#">添加公告</a>
            </li>
        </ul>
    </div>
</div>


<!--编辑公告-->

<form name="myform" id="myform" action="#" enctype="multipart/form-data">


    <ul class="edit-list">
        <li>公告名称：</li>
        <li>公告图片：</li>
        <li><label for="newsCheckbox">是否标记为轮播图：</label></li>
    </ul>


    <ul class="edit-list">
        <li><input type="text" name="title" id="title" class="input-text"/></li>
        <li><input type="file" name="file" id="file" class="file"/></li>
        <li><input type="checkbox" name="isMarkAsThumbnail" value="isMarkAsThumbnail" id="newsCheckbox"/></li>
    </ul>


    <div style="clear: both"></div>

    <div style="margin-left: 20px">

           <textarea id="editor_id" name="content"
                     style="width: 80%; max-width: 1000px; height: 400px; display: none;margin-left: 130px">

    </textarea>

    </div>


</form>


<div class="add_btn">
    <button class="btn ml17 btn-primary" onclick="addNew()">提交</button>
</div>


</body>
<script type="text/javascript">
    $(function () {
        //图片文件大小控制
        $("#file").change(function () {
            var fileInput = $("#file")[0];
            var byteSize = fileInput.files[0].size;
            if (byteSize > 1024 * 1024) {
                alert("图片大小超过1M");
                $("#file").val("");
            }
        });
    });

    function addNew() {
        var newsContent = $('#editor_id').val();
        var newsTitle = $(".input-text").val();
        var formData = new FormData();
        formData.append('file', $('#file')[0].files[0]);
        formData.append('title', newsTitle);
        formData.append('content', newsContent);
        if ($('#newsCheckbox').prop("checked")) {
            formData.append('isMarkAsThumbnail', $('#newsCheckbox').val());
        }
        $.ajax({
            type: "POST",
            url: v2 + "/news",
            data: formData,
            processData: false,
            contentType: false,
            success: function (json) {
                if (json.meta.code == "200") {
                    alert("添加成功！");
                    layer.close(index);
                    window.location.reload();
                }
            },
            error: function (data) {
                alert("error:" + "添加失败，可能未选择文件");
            }
        });
    }
</script>
</html>